/**
 *
 * @param table {Table}
 * @param auth {boolean} 接口是否需要鉴权
 * @param uninstall {boolean} 是否在生成代码时注释该方法，用于备用
 * @returns {string}
 */
const deleteById = (table, auth = false, uninstall = false) => {
  const {
    comment,
    idType,
    existUpdateTimeColumn,
    author
  } = table
  const authUserId = auth ? ', user.getId()' : ''
  return `// <-
    @DeleteMapping("/{encryptId}")
    //@PreAuthorize("hasAnyAuthority('ROLE_ADMIN', 'ROLE_ADMIN_TEST', '{}_delete')")
    @ApiOperation(value = "${table.incrementAndGetOrdered()}.物理删除${comment}", tags = {""})
    @ApiOperationSupport(order = ${table.ordered}, author = "${author}")
    @ResponseBody
    public Result<Void> deleteById(
            @ApiIgnore @AuthenticationPrincipal final IUser user,
            @ApiParam(required = true, value = "加密id", example = "encryptId") @PathVariable final String encryptId) {
        return new Result<Void>().call(() -> {
            final AesApiId.AesId decrypt = AesApiId.decrypt(encryptId);
            service.deleteById(decrypt.get${idType}Id()${authUserId});
        });
    }
    
    @DeleteMapping
    //@PreAuthorize("hasAnyAuthority('ROLE_ADMIN', 'ROLE_ADMIN_TEST', '{}_delete')")
    @ApiOperation(value = "${table.incrementAndGetOrdered()}.物理删除${comment}", tags = {""})
    @ApiOperationSupport(
            order = ${table.ordered},
            author = "${author}",
            params = @DynamicParameters(name = "EncryptIdArray", properties = {
                    @DynamicParameter(name = "EncryptIdArray", value = "加密id", example = "[encryptId,encryptId]", required = true, dataTypeClass = String[].class)
            })
    )
    @ResponseBody
    public Result<Void> deleteByIds(
            @ApiIgnore @AuthenticationPrincipal final IUser user,
            @RequestBody final Set<String> body
    ) {
        return new Result<Void>().call(() -> {
            Code.A00002.assertNonEmpty(body, "请至少选择一条数据");
            final List<AesApiId.AesId> decryptList = body.stream().map(AesApiId::decrypt).collect(Collectors.toList());
            service.deleteByIds(
                    decryptList.stream().map(AesApiId.AesId::get${idType}Id).collect(Collectors.toSet())
                    ${existUpdateTimeColumn ? '' : '//'}, decryptList.stream().map(AesApiId.AesId::getUpdateTime).collect(Collectors.toSet())
                    , user.getId()
            );
        });
    }
`.split('\n')
    .map(row => (uninstall ? '//' : '') + row)
    .join('\n')
}
export const deleteByIdOpenInstall = table => deleteById(table)
export const deleteByIdOpenUninstall = table => deleteById(table, false, true)

export const deleteByIdAuthInstall = table => deleteById(table, true, false)
export const deleteByIdAuthUninstall = table => deleteById(table, true, true)
